package com.heima.user.service;

import com.heima.cloud.clients.OrderFeignApi;
import com.heima.cloud.pojo.Order;
import com.heima.cloud.pojo.User;
import com.heima.cloud.vo.UserVo;
import com.heima.user.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {

    @Autowired
    private OrderFeignApi orderFeignApi;

    @Autowired
    private UserMapper userMapper;

    public User queryByName(String username) {
//        try {
//            Thread.sleep(2100);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        if ("itheima".equals(username)) {
            throw new RuntimeException("itheima");
        }

        return userMapper.findById(username);
    }

    public UserVo findOrderByUserId(String username) {
        UserVo userVo=new UserVo();
        User user = userMapper.findById(username);
        userVo.setBirthday(user.getBirthday());
        userVo.setCreated(user.getCreated());
        userVo.setEmail(user.getEmail());
        userVo.setExperienceValue(user.getExperienceValue());
        userVo.setUsername(username);
        userVo.setOrders(orderFeignApi.findOrderByUserId(username));
        return userVo;
    }
}
